package com.liuxvru.project.user.controller;

import com.liuxvru.common.annotation.Log;
import com.liuxvru.common.core.controller.BaseController;
import com.liuxvru.common.core.domain.AjaxResult;
import com.liuxvru.common.core.page.TableDataInfo;
import com.liuxvru.common.enums.BusinessType;
import com.liuxvru.common.utils.poi.ExcelUtil;
import com.liuxvru.project.domain.Sprint;
import com.liuxvru.project.service.ISprintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * SprintController
 *
 * @author liuxvru
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/user/project/sprint")
public class UserSprintController extends BaseController {
    @Autowired
    private ISprintService sprintService;

    /**
     * 查询Sprint列表
     */
    @GetMapping("/list/{projectId}")
    public TableDataInfo list(@PathVariable("projectId") Long projectId, Sprint sprint) {
        startPage();
        sprint.setProjectId(projectId);
        List<Sprint> list = sprintService.selectSprintList(sprint);
        return getDataTable(list);
    }
    /**
     * 查询Sprint列表
     */
    @GetMapping("/listAll/{projectId}")
    public AjaxResult listAll(@PathVariable("projectId") Long projectId, Sprint sprint) {
        sprint.setProjectId(projectId);
        List<Sprint> list = sprintService.selectSprintList(sprint);
        return success(list);
    }

    /**
     * 导出Sprint列表
     */
    @Log(title = "Sprint", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Sprint sprint) {
        List<Sprint> list = sprintService.selectSprintList(sprint);
        ExcelUtil<Sprint> util = new ExcelUtil<Sprint>(Sprint.class);
        util.exportExcel(response, list, "Sprint数据");
    }

    /**
     * 获取Sprint详细信息
     */
    @GetMapping(value = "/{sprintId}")
    public AjaxResult getInfo(@PathVariable("sprintId") Long sprintId) {
        return success(sprintService.getById(sprintId));
    }

    /**
     * 新增Sprint
     */
    @Log(title = "Sprint", businessType = BusinessType.INSERT)
    @PostMapping("{projectId}")
    public AjaxResult add(@PathVariable("projectId") Long projectId, @RequestBody Sprint sprint) {
        return toAjax(sprintService.add(projectId, sprint));
    }

    /**
     * 修改Sprint
     */
    @Log(title = "Sprint", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Sprint sprint) {
        return toAjax(sprintService.updateById(sprint));
    }

    /**
     * 删除Sprint
     */
    @Log(title = "Sprint", businessType = BusinessType.DELETE)
    @DeleteMapping("/{sprintIds}")
    public AjaxResult remove(@PathVariable Long[] sprintIds) {
        return toAjax(sprintService.removeById(sprintIds));
    }

    /**
     * 查询没有发布的迭代
     */
    @Log(title = "发布", businessType = BusinessType.INSERT)
    @GetMapping("/getNoReleaseSprint/{releaseId}")
    public AjaxResult getNoReleaseSprint(@PathVariable("releaseId") Long releaseId) {
        return success(sprintService.getNoReleaseSprint(releaseId));
    }
}
